package com.project.filter;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Locale;

/**
 * @Author(王思翰)
 * @Description(类的描述)
 * @Date(创建时间) 2021/7/29 16:46
 */
public class CharFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest,
                         ServletResponse servletResponse,
                         FilterChain filterChain) throws IOException, ServletException {
        //设置请求编码集，只对POST有效
        servletRequest.setCharacterEncoding("utf-8");
        servletResponse.setContentType("test/html;charset=utf-8");

        HttpServletRequest request = (HttpServletRequest) servletRequest;
        filterChain.doFilter(request, servletResponse);
    }
//
//    private class MyRequest extends HttpServletRequestWrapper {
//        private HttpServletRequest request;
//        public MyRequest(HttpServletRequest request) {
//            super(request);
//            this.request=request;
//        }
//
//        @Override
//        public String getParameter(String name) {
//            String value=request.getParameter(name);
//            if (name.indexOf("他妈的")!=-1){
//                value=value.replaceAll("他妈的","***");
//            }
//            return value;
//        }
//    }
}